const Command = require('../command.js')
const initCli = require('../../bin/cli-init')
const chalk = require('chalk')

const description = `xz-cli init [xxx]: 输入初始化项目的名称，如果没有名称，模板注入到当前目录中`

class InitCommand extends Command {
  constructor(rawArgv) {
    super(rawArgv)
  }

  * run ({ argv }) {
    const dirName = argv._[0]

    if (!argv._[0]) {
      console.log('')
      console.log(chalk.red('❗ 未检测到项目名称，模板将注入到当前目录中'))
      console.log('')
    } else {
      console.log('')
      console.log(`项目名称: ${chalk.green(dirName)}`)
      console.log('')
    }

    initCli(dirName)
  }

  get description () {
    return description
  }

}

module.exports = InitCommand